/*
* pps_bom
*/
package com.pitop.bom.ctrl;


import com.alibaba.fastjson.JSON;
import com.pitop.bom.entity.BomLog;
import com.pitop.bom.service.BomLogSVImpl;
import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.tools.redis.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * bom日志 控制器
 *
 * @author berton
 */
@RestController
@RequestMapping("/bomLog")
@Slf4j
@Api(value = "bom日志控制器", description = "bom日志控制器")
public class BomLogCtrl {

    @Resource
    protected RedisUtils redisUtils;
    @Autowired
    private BomLogSVImpl bomLogSVImpl;


    /**
     * 查询BomLog一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询BomLog一个详情信息", notes = "查询BomLog一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(Long id) {
        if (id == null) {
            return null;
        }
        BomLog bomLog = bomLogSVImpl.load(id);
        log.info(JSON.toJSONString(bomLog));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, bomLog);
    }

    /**
     * 查询BomLog一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询BomLog一个详情信息", notes = "查询BomLog一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query")
    })
    @GetMapping(value = "/get")
    @ResponseBody
    public BeanRet get(Long id) {
        if (id == null) {
            return null;
        }
        BomLog bomLog = bomLogSVImpl.get(id);
        log.info(JSON.toJSONString(bomLog));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, bomLog);
    }


    /**
     * 根据条件id查询BomLog一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询BomLog一个详情信息", notes = "查询BomLog一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable Long id) {
        if (id == null || id == 0) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        BomLog bomLog = bomLogSVImpl.loadById(id);
        log.info(JSON.toJSONString(bomLog));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, bomLog);
    }

    /**
     * 根据条件id查询BomLog一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询BomLog一个详情信息", notes = "查询BomLog一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/get/id/{id}")
    @ResponseBody
    public BeanRet getById(@PathVariable Long id) {
        if (id == null || id == 0) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        BomLog bomLog = bomLogSVImpl.getById(id);
        log.info(JSON.toJSONString(bomLog));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, bomLog);
    }

    /**
     * 查询BomLog信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询BomLog信息集合", notes = "查询BomLog信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "sortColumns", value = "排序：倒叙：createTime DESC, 正序：createTime ASC", paramType = "query"),
            @ApiImplicitParam(name = "createTimeBegin", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "createTimeEnd", value = "创建时间", paramType = "query")
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore BomLog bomLog, @ApiIgnore Page<BomLog> page) {
        if (page == null) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        List<BomLog> bomLogs = bomLogSVImpl.list(bomLog, page.getCurPage(), page.getPageSize());
        int total = bomLogSVImpl.count(bomLog);
        page.setTotalRow(total);
        page.setVoList(bomLogs);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, "", page);
    }

    /**
     * 查询BomLog信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询BomLog信息集合", notes = "查询BomLog信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(Long id, @ApiIgnore Page<BomLog> page) {
        if (page == null) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        List<BomLog> bomLogs = bomLogSVImpl.list(id, page.getCurPage(), page.getPageSize());
        int total = bomLogSVImpl.count(id);
        page.setTotalRow(total);
        page.setVoList(bomLogs);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, "", page);
    }

    /**
     * 创建BomLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建BomLog", notes = "创建BomLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "bomCode", value = "bom编码", paramType = "query"),
            @ApiImplicitParam(name = "event", value = "事件定义[修改 Update,删除 Delete,创建 Create,复制 Copy,禁用 Stop]", paramType = "query"),
            @ApiImplicitParam(name = "operateCode", value = "操作人编码", paramType = "query"),
            @ApiImplicitParam(name = "operateName", value = "操作人", paramType = "query"),
            @ApiImplicitParam(name = "summary", value = "日志描述", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore BomLog bomLog) {
        if (StringUtils.isEmpty(bomLog.getBomCode())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(bomLog.getEvent())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(bomLog.getOperateCode())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(bomLog.getOperateName())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(bomLog.getSummary())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        bomLogSVImpl.save(bomLog);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, bomLog);
    }

    /**
     * 修改BomLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改BomLog", notes = "修改BomLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "bomCode", value = "bom编码", paramType = "query"),
            @ApiImplicitParam(name = "event", value = "事件定义[修改 Update,删除 Delete,创建 Create,复制 Copy,禁用 Stop]", paramType = "query"),
            @ApiImplicitParam(name = "operateCode", value = "操作人编码", paramType = "query"),
            @ApiImplicitParam(name = "operateName", value = "操作人", paramType = "query"),
            @ApiImplicitParam(name = "summary", value = "日志描述", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore BomLog bomLog) {
        if (StringUtils.isEmpty(bomLog.getBomCode())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(bomLog.getEvent())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(bomLog.getOperateCode())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(bomLog.getOperateName())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(bomLog.getSummary())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        bomLogSVImpl.modify(bomLog);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, bomLog);
    }

    /**
     * 根据主键删除BomLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除BomLog", notes = "删除BomLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id) {
        if (id != null) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }

        bomLogSVImpl.delete(id);
        return BeanRet.create(true, "删除BomLog成功");
    }

}
